package com.qst.rongxiaoserver.controller;

import com.qst.rongxiaoserver.common.Result;
import com.qst.rongxiaoserver.model.OrderModel;
import com.qst.rongxiaoserver.service.IOrderService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/order")
@Tag(name = "订单管理", description = "订单管理")
public class OrderController {

    @Autowired
    IOrderService orderService;

    // 购买商品， 生成订单
    @PostMapping("/set")
    @Operation(summary = "生成订单", description = "购买商品(服务层实现)")
    public Result set(@Valid @RequestBody OrderModel orderModel) {
        boolean isSave =  orderService.createOrder(orderModel);
        return isSave? Result.success("下单成功"):Result.fail("下单失败");
     //    购买  =  下单 + 支付
    }

    // 删除订单
    @PostMapping("/delete")
    @Operation(summary = "删除订单", description = "删除订单(服务层实现)")
    public Result delete(@Valid @RequestParam Integer id) {
        boolean isDelete =  orderService.removeById(id);
        return isDelete? Result.success("删除成功"):Result.fail("删除失败");
    }
}
